package simulateOS.entity;

import javafx.beans.property.*;
import javafx.scene.control.ProgressBar;
import lombok.Data;

/**
 * Description：进程
 * Date: 2022/9/27
 * Time: 13:51
 *
 * @Author SillyBaka
 **/

public class Process {
    /**
     * 进程控制块
     */
    private ObjectProperty<PCB> pcb;
    /**
     * 进程状态
     */
    private ObjectProperty<Status> status;
    /**
     * 运行所需内存空间大小
     */
    private IntegerProperty size;
    /**
     * 运行进度条
     */
    private ObjectProperty<ProgressBar> progressBar;
    /**
     * 设备
     */
    private ObjectProperty<Device> device;
    /**
     * 进程所在的分区
     */
    private Partition partition;

    /**
     * 提交时间
     */
    private DoubleProperty submitTime;

    /**
     * 总运行时间
     */
    private DoubleProperty runningTime;

    /**
     * 结束时间
     */
    private DoubleProperty destroyTime;

    /**
     * 运行结果
     */
    private IntegerProperty runResult;

    public Process(){
        pcb = new SimpleObjectProperty<>();
        status = new SimpleObjectProperty<>();
        size = new SimpleIntegerProperty();
        progressBar = new SimpleObjectProperty<>();
        device = new SimpleObjectProperty<>();
        submitTime = new SimpleDoubleProperty(0);
        runningTime = new SimpleDoubleProperty(0);
        destroyTime = new SimpleDoubleProperty(0);
        runResult = new SimpleIntegerProperty(0);
        ProgressBar progressBar = new ProgressBar();

        device.set(Device.DEFAULT_DEVICE);
    }


    public void refreshProgress(){
        // todo 刷新进度条
//        this.progressBar.get().setProgress();
    }


    public void setPcb(PCB pcb) {
        this.pcb.set(pcb);
    }

    public void setSubmitTime(double submitTime) {
        this.submitTime.set(submitTime);
    }

    public void setStatus(Status status) {
        this.status.set(status);
    }

    public void setDevice(Device device) {
        this.device.set(device);
    }

    public Status getStatus() {
        return status.get();
    }

    public ObjectProperty<Status> statusProperty() {
        return status;
    }

    public double getSubmitTime() {
        return submitTime.get();
    }

    public DoubleProperty submitTimeProperty() {
        return submitTime;
    }

    public double getRunningTime() {
        return runningTime.get();
    }

    public DoubleProperty runningTimeProperty() {
        return runningTime;
    }

    public double getDestroyTime() {
        return destroyTime.get();
    }

    public DoubleProperty destroyTimeProperty() {
        return destroyTime;
    }

    public PCB getPcb() {
        return pcb.get();
    }

    public ObjectProperty<PCB> pcbProperty() {
        return pcb;
    }

    public void setRunResult(int runResult) {
        this.runResult.set(runResult);
    }

    public ProgressBar getProgressBar() {
        return progressBar.get();
    }

    public ObjectProperty<ProgressBar> progressBarProperty() {
        return progressBar;
    }

    public int getSize() {
        return size.get();
    }

    public IntegerProperty sizeProperty() {
        return size;
    }

    public Device getDevice() {
        return device.get();
    }

    public ObjectProperty<Device> deviceProperty() {
        return device;
    }

    public Partition getPartition() {
        return partition;
    }

    public int getRunResult() {
        return runResult.get();
    }

    public IntegerProperty runResultProperty() {
        return runResult;
    }

    public void setSize(int size) {
        this.size.set(size);
    }

    public void setProgressBar(ProgressBar progressBar) {
        this.progressBar.set(progressBar);
    }

    public void setProgressBarValue(double progress) {
        this.progressBar.getValue().setProgress(progress);
    }

    public void setPartition(Partition partition) {
        this.partition = partition;
    }

    public void setRunningTime(double runningTime) {
        this.runningTime.set(runningTime);
    }

    public void setDestroyTime(double destroyTime) {
        this.destroyTime.set(destroyTime);
    }
}
